package com.iseastar.guojiang.register;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.iseastar.BaseActivity2;
import com.iseastar.dianxiaosan.model.Const;
import com.iseastar.guojiang.app.AppCache;
import com.iseastar.guojiang.model.UserBean;
import com.shouhuobao.station.R;

import droid.frame.ui.utils.Utils;

/**
 * 注册火箭侠步骤
 * Created by lidandan on 2018/4/28.
 */
public class RegisterCourierStepActivity extends BaseActivity2 implements View.OnClickListener {

    private TextView mStep1RightTV;
    private LinearLayout mStep2LL;
    private TextView mStep2TitleTV;
    private TextView mStep2ContentTV;
    private TextView mStep2RightTV;
    private LinearLayout mStep3LL;
    private TextView mStep3TitleTV;
    private TextView mStep3ContentTV;
    private TextView mStep3RightTV;
    private UserBean item;

    @SuppressLint("MissingSuperCall")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        item = (UserBean) getIntent().getSerializableExtra("item");
        if (item == null) {
            item = AppCache.getUser();
        }
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.register_courier_step_activity);
        super.findViewById();
        getAppTitle().setCommonTitle("火箭侠");
        //步骤一
        findViewById(R.id.register_step1_ll).setOnClickListener(this);
        mStep1RightTV = (TextView) findViewById(R.id.register_step1_right_tv);
        //步骤二
        mStep2LL = (LinearLayout) findViewById(R.id.register_step2_ll);
        mStep2LL.setOnClickListener(this);
        mStep2TitleTV = (TextView) findViewById(R.id.register_step2_title_tv);
        mStep2ContentTV = (TextView) findViewById(R.id.register_step2_content_tv);
        mStep2RightTV = (TextView) findViewById(R.id.register_step2_right_tv);
        //步骤三
        mStep3LL = (LinearLayout) findViewById(R.id.register_step3_ll);
        mStep3LL.setOnClickListener(this);
        mStep3TitleTV = (TextView) findViewById(R.id.register_step3_title_tv);
        mStep3ContentTV = (TextView) findViewById(R.id.register_step3_content_tv);
        mStep3RightTV = (TextView) findViewById(R.id.register_step3_right_tv);
        stepShowStatus();
    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
            //步骤一
            case R.id.register_step1_ll:
                if (item == null || item.getState() == Const.CourierRegisterStatus.RegisterStatus || item.getCourierAudit() == null
                        || item.getCourierAudit().getAuditStatus() == 0 || item.getCourierAudit().getAuditStatus() == 3) {
                    intent = new Intent(this, CourierPerfectInformationActivity.class);
                    startActivityForResult(intent, 1501);
                } else {
                    intent = new Intent(getContext(), CourierPerfectInfoDetailActivity.class);
                    intent.putExtra("item", item);
                    startActivity(intent);
                }
                break;
            //步骤二
            case R.id.register_step2_ll:
                intent = new Intent(this, RegisterBusinessTrainingActivity.class);
                intent.putExtra("item", item);
                startActivityForResult(intent, 1502);
                break;
            //步骤三
            case R.id.register_step3_ll:
                intent = new Intent(this, RegisterCourierMaterialActivity.class);
                intent.putExtra("item", item);
                startActivityForResult(intent, 1504);
                break;
        }
    }

    /**
     * 步骤布局更新
     */
    public void stepShowStatus() {
        Drawable drawableRight = getResources().getDrawable(R.drawable.arrow_right_eeeeee);
        if (item == null || item.getCourierAudit() == null) {
            return;
        }
        switch (item.getState()) {
            case Const.CourierRegisterStatus.RegisterStatus:
                //步骤一
                mStep1RightTV.setText("请填写");
                //步骤二
                mStep2LL.setEnabled(false);
                mStep2LL.setBackgroundResource(R.drawable.register_courier_stap_eeeeee_bg);
                mStep2TitleTV.setTextColor(Color.parseColor("#c9c9c9"));
                mStep2ContentTV.setTextColor(Color.parseColor("#c9c9c9"));
                mStep2RightTV.setText("");
                mStep2RightTV.setTextColor(Color.parseColor("#c9c9c9"));
                mStep2RightTV.setCompoundDrawablesWithIntrinsicBounds(null, null, drawableRight, null);
                mStep2RightTV.setCompoundDrawablePadding(Utils.dpToPx(6, getResources()));
                //步骤三
                mStep3LL.setEnabled(false);
                mStep3LL.setBackgroundResource(R.drawable.register_courier_stap_eeeeee_bg);
                mStep3TitleTV.setTextColor(Color.parseColor("#c9c9c9"));
                mStep3ContentTV.setTextColor(Color.parseColor("#c9c9c9"));
                mStep3RightTV.setText("");
                mStep3RightTV.setTextColor(Color.parseColor("#c9c9c9"));
                mStep3RightTV.setCompoundDrawablesWithIntrinsicBounds(null, null, drawableRight, null);
                mStep3RightTV.setCompoundDrawablePadding(Utils.dpToPx(6, getResources()));
                break;
            /**
             * 完善资料：分为四种状态，填写状态、审核中、通过审核、审核失败
             */
            case Const.CourierRegisterStatus.AuditStatus:
                if (item.getCourierAudit().getAuditStatus() == 2) {
                    //步骤一
                    mStep1RightTV.setText("通过审核");
                    //步骤二
                    mStep2LL.setEnabled(true);
                    mStep2LL.setBackgroundResource(R.drawable.register_courier_step_c9c9c9_bg);
                    mStep2TitleTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep2ContentTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep2RightTV.setText("前往预约");
                    mStep2RightTV.setTextColor(Color.parseColor("#4a4a4a"));
                    //步骤三
                    mStep3LL.setEnabled(false);
                    mStep3LL.setBackgroundResource(R.drawable.register_courier_stap_eeeeee_bg);
                    mStep3TitleTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep3ContentTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep3RightTV.setText("");
                    mStep3RightTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep3RightTV.setCompoundDrawablesWithIntrinsicBounds(null, null, drawableRight, null);
                    mStep3RightTV.setCompoundDrawablePadding(Utils.dpToPx(6, getResources()));
                } else {
                    if (item.getCourierAudit().getAuditStatus() == 0) {
                        mStep1RightTV.setText("请填写");
                    } else if (item.getCourierAudit().getAuditStatus() == 1) {
                        mStep1RightTV.setText("审核中");
                    } else if (item.getCourierAudit().getAuditStatus() == 3) {
                        mStep1RightTV.setText("审核未通过");
                    }
                    mStep2LL.setEnabled(false);
                    mStep2LL.setBackgroundResource(R.drawable.register_courier_stap_eeeeee_bg);
                    mStep2TitleTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep2ContentTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep2RightTV.setText("");
                    mStep2RightTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep2RightTV.setCompoundDrawablesWithIntrinsicBounds(null, null, drawableRight, null);
                    mStep2RightTV.setCompoundDrawablePadding(Utils.dpToPx(6, getResources()));
                    //步骤三
                    mStep3LL.setEnabled(false);
                    mStep3LL.setBackgroundResource(R.drawable.register_courier_stap_eeeeee_bg);
                    mStep3TitleTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep3ContentTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep3RightTV.setText("");
                    mStep3RightTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep3RightTV.setCompoundDrawablesWithIntrinsicBounds(null, null, drawableRight, null);
                    mStep3RightTV.setCompoundDrawablePadding(Utils.dpToPx(6, getResources()));
                }
                break;
            /**
             * 参加培训：分为三种状态，前往预约、已预约、培训通过
             */
            case Const.CourierRegisterStatus.TrainStatus:
                if (item.getCourierAudit().getTrainStatus() == 3) {
                    //步骤一
                    mStep1RightTV.setText("通过审核");
                    //步骤二
                    mStep2LL.setEnabled(true);
                    mStep2LL.setBackgroundResource(R.drawable.register_courier_step_c9c9c9_bg);
                    mStep2TitleTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep2ContentTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep2RightTV.setText("培训通过");
                    mStep2RightTV.setTextColor(Color.parseColor("#4a4a4a"));
                    //步骤三
                    mStep2LL.setEnabled(true);
                    mStep3LL.setBackgroundResource(R.drawable.register_courier_step_c9c9c9_bg);
                    mStep3TitleTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep3ContentTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep3RightTV.setText("前往查看");
                    mStep3RightTV.setTextColor(Color.parseColor("#4a4a4a"));
                } else {
                    if (item.getCourierAudit().getTrainStatus() == 1) {
                        mStep2RightTV.setText("前往预约");
                    } else if (item.getCourierAudit().getTrainStatus() == 2) {
                        mStep2RightTV.setText("预约成功");
                    }
                    //步骤一
                    mStep1RightTV.setText("通过审核");
                    //步骤二
                    mStep2LL.setEnabled(true);
                    mStep2LL.setBackgroundResource(R.drawable.register_courier_step_c9c9c9_bg);
                    mStep2TitleTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep2ContentTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep2RightTV.setTextColor(Color.parseColor("#4a4a4a"));
                    //步骤三
                    mStep3LL.setEnabled(false);
                    mStep3LL.setBackgroundResource(R.drawable.register_courier_stap_eeeeee_bg);
                    mStep3TitleTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep3ContentTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep3RightTV.setText("");
                    mStep3RightTV.setTextColor(Color.parseColor("#c9c9c9"));
                    mStep3RightTV.setCompoundDrawablesWithIntrinsicBounds(null, null, drawableRight, null);
                    mStep3RightTV.setCompoundDrawablePadding(Utils.dpToPx(6, getResources()));
                }
                break;
            /**
             * 领取物料：分为两种状态，没有支付押金、已支付
             */
            case Const.CourierRegisterStatus.ReceiveStatus:
            case Const.CourierRegisterStatus.DepositStatus:
                if (item.getCourierAudit().getDepositStatus() == 1 || item.getCourierAudit().getReceiveStatus() == 1) {
                    //步骤一
                    mStep1RightTV.setText("通过审核");
                    //步骤二
                    mStep2LL.setEnabled(true);
                    mStep2LL.setBackgroundResource(R.drawable.register_courier_step_c9c9c9_bg);
                    mStep2TitleTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep2ContentTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep2RightTV.setText("培训通过");
                    mStep2RightTV.setTextColor(Color.parseColor("#4a4a4a"));
                    //步骤三
                    mStep2LL.setEnabled(true);
                    mStep3LL.setBackgroundResource(R.drawable.register_courier_step_c9c9c9_bg);
                    mStep3TitleTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep3ContentTV.setTextColor(Color.parseColor("#4a4a4a"));
                    mStep3RightTV.setText("前往查看");
                    mStep3RightTV.setTextColor(Color.parseColor("#4a4a4a"));
                }
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != Activity.RESULT_OK) {
            return;
        }
        //身份证提交返回,预约培训返回
        if (requestCode == 1501 || requestCode == 1502) {
            item = AppCache.getUser();
            stepShowStatus();
        }
        if (1504 == requestCode) {
            finish();
        }

    }
}
